package com.lcredu.furn.service.impl;

import com.lcredu.furn.bean.Furn;
import com.lcredu.furn.bean.FurnExample;
import com.lcredu.furn.dao.FurnMapper;
import com.lcredu.furn.service.FurnService;
import com.sun.org.apache.bcel.internal.generic.NEW;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;

/**
 * @author 黎长容
 * @date 2025-08-04 19:19
 */
@Service
public class FurnServiceImpl implements FurnService {
    @Resource
    private FurnMapper furnMapper;

    @Override
    public void save(Furn furn) {
        furnMapper.insertSelective(furn);
    }

    @Override
    public List<Furn> findAll() {
        return furnMapper.selectByExample(null);
    }

    @Override
    public void editFurn(Furn furn) {
        furnMapper.updateByPrimaryKeySelective(furn);
    }

    @Override
    public Furn getFurnById(Integer furnId) {
        Furn furn = furnMapper.selectByPrimaryKey(furnId);
        return furn;
    }

    @Override
    public void deleteFurn(Integer furnId) {
        int deleted = furnMapper.deleteByPrimaryKey(furnId);
//        return deleted > 0 ? true : false;
    }

    @Override
    public List<Furn> findByCondition(String name) {
        FurnExample furnExample = new FurnExample();
        FurnExample.Criteria criteria = furnExample.createCriteria();
        if (StringUtils.hasText(name)) {
            criteria.andNameLike("%" + name + "%");
        }
        return furnMapper.selectByExample(furnExample);
    }
}
